var db = require('../utils/db');

var roomInfo = {};
var roomUUid = {};

//初始房间数据
exports.initRoomInfo = function()
{
    db.get_valid_room_info(function(room_info,room_uuid){
        for (var key in room_info)
        {
            roomInfo[key] = room_info[key];
        }
        for (var key in room_uuid)
        {
            roomUUid[key] = room_uuid[key];
        }
    });
}

//根据ID获取房间信息
exports.getRoomInfoById = function(roomId)
{
    return roomInfo[roomId];
}

//存入房间信息
exports.storeNewRoom = function(roominfo)
{
    if (roomInfo[roominfo.id] == null)
    {
        roomInfo[roominfo.id] = roominfo;
    }
}

//更新房间信息
exports.update = function()
{
    db.get_valid_room_info(function(room_info,room_uuid){
        for (var key in room_info)
        {
            roomInfo[key] = room_info[key];
        }
        for (var key in room_uuid)
        {
            roomUUid[key] = room_uuid[key];
        }
        for (var key in roomInfo)
        {
            if (room_info[key] == null)
            {
                roomInfo[key] = null;
            }
        }
        for (var key in roomUUid)
        {
            if (room_uuid[key] == null)
            {
                roomUUid[key] = null;
            }
        }
    });
}